﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage.VoteManage
{
    public partial class vote_action : System.Web.UI.Page
    {
        VoteTopicBLL vtbll = new VoteTopicBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            string op = Request["op"];
            if (op.ToLower() == "del")
            {
                int id = Convert.ToInt32(Request["id"]);
                if (vtbll.Delete("VoteTopic", id))
                {
                    Response.Write("1");
                }
                else
                {
                    Response.Write("fail");
                }

            }
            if (op.ToLower() == "deloption")
            {
                VoteOptionBLL vobll = new VoteOptionBLL();

                int id = Convert.ToInt32(Request["id"]);
                VoteOption vo = (VoteOption)vobll.FindModelById("VoteOption", id);
                VoteTopic vt = (VoteTopic)vtbll.FindModelById("VoteTopic", vo.VoteTopicId);
                if (vobll.Delete("VoteOption", id))
                {
                    IList<VoteOption> volist = new List<VoteOption>();
                    volist = vobll.GetListByPager(-1, 1, vt.Id);
                    int clickcount = 0;
                    foreach (VoteOption vv in volist)
                    {
                        clickcount += vv.ClickCount;
                    }
                    vt.ClickCount = clickcount;
                    vtbll.entity = vt;
                    vtbll.UpDate();
                    Response.Write("1");
                }
                else
                {
                    Response.Write("fail");
                }

            }

        }
    }
}
